﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Collections.ObjectModel;

#if SILVERLIGHT
    using System.Windows.Controls;
#endif

namespace BusinessObjects
{
    [DataContract]
    public class Player : GameObject
    {
        private int userId;
        private double actualX;
        private double actualY;
        private int mapId;
        private string name;
        private string badges;
        private bool isMainPlayer;
        private string quests;
        private int kidControlId;
        private bool isGuest = false;

        private ObservableCollection<Event> questsCollection;
        private ObservableCollection<UserBadge> badgesCollection;
        private ObservableCollection<Player> playerConnections;
        // workaround - expose a list to convert easy to a collection of images
        private ObservableCollection<int> gameLevelCollectionWorkaround;

        private ObservableCollection<int> connections;
        private int experience;
        private double rationedExperience;
        private int level;

        [DataMember]
        public int MapId
        {
            get
            {
                return this.mapId;
            }
            set
            {
                if ( this.mapId == value )
                    return;

                this.mapId = value;
                this.NotifyPropertyChanged( "MapId" );
            }
        }

#if SILVERLIGHT
        [XmlIgnore]
        public ContentPresenter ContentItemn
        {
            get;
            set;
        }
#endif
        [DataMember]
        public double ActualX
        {
            get
            {
                return this.actualX;
            }
            set
            {
                if ( this.actualX == value )
                    return;

                this.actualX = value;
                this.NotifyPropertyChanged( "ActualX" );
            }
        }

        [DataMember]
        public double ActualY
        {
            get
            {
                return this.actualY;
            }
            set
            {
                if ( this.actualY == value )
                    return;

                this.actualY = value;
                this.NotifyPropertyChanged( "ActualY" );
            }
        }

        [DataMember]
        public bool IsMainPlayer
        {
            get
            {
                return this.isMainPlayer;
            }
            set
            {
                if ( this.isMainPlayer == value )
                    return;

                this.isMainPlayer = value;
                this.NotifyPropertyChanged( "IsMainPlayer" );
            }
        }

        [DataMember]
        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                if ( this.name == value )
                    return;

                this.name = value;
                this.NotifyPropertyChanged( "Name" );
            }
        }

        [DataMember]
        public string Badges
        {
            get
            {
                return this.badges;
            }
            set
            {
                if ( this.badges == value )
                    return;

                this.badges = value;
                this.NotifyPropertyChanged( "Badges" );
            }
        }

        [DataMember]
        public string Quests
        {
            get
            {
                return this.quests;
            }
            set
            {
                if ( this.quests == value )
                    return;

                this.quests = value;
                this.NotifyPropertyChanged( "Quests" );
            }
        }

        [DataMember]
        public int KidControlId
        {
            get
            {
                return this.kidControlId;
            }
            set
            {
                if ( this.kidControlId == value )
                    return;

                this.kidControlId = value;
                this.NotifyPropertyChanged( "KidControlId" );
            }
        }

        /// <summary>
        /// The Player Ids to whom this player is connected
        /// </summary>
        public ObservableCollection<int> Connections
        {
            get
            {
                if ( this.connections == null )
                    this.connections = new ObservableCollection<int>();

                return this.connections;
            }
            set
            {
                if ( this.connections == value )
                    return;

                this.connections = value;
                this.NotifyPropertyChanged( "Connections" );
            }
        }

        [DataMember]
        public int Experience
        {
            get
            {
                return this.experience;
            }
            set
            {
                if ( this.experience == value )
                    return;

                this.experience = value;
                this.NotifyPropertyChanged( "Experience" );
            }
        }

        [DataMember]
        public int Level
        {
            get
            {
                return this.level;
            }
            set
            {
                if ( this.level == value )
                    return;

                this.level = value;
                this.NotifyPropertyChanged( "Level" );
            }
        }

        [DataMember]
        public bool IsGuest
        {
            get
            {
                return this.isGuest;
            }
            set
            {
                if ( this.isGuest == value )
                    return;

                this.isGuest = value;
                this.NotifyPropertyChanged( "IsGuest" );
            }
        }

        [DataMember]
        public int UserId
        {
            get
            {
                return this.userId;
            }
            set
            {
                if ( this.userId == value )
                    return;

                this.userId = value;
            }
        }

        [XmlIgnore]
        public ObservableCollection<Event> QuestsCollection
        {
            get
            {
                if ( this.questsCollection == null )
                    this.questsCollection = new ObservableCollection<Event>();

                return this.questsCollection;
            }
            set
            {
                if ( this.questsCollection != value )
                {
                    this.questsCollection = value;
                    this.NotifyPropertyChanged( "QuestsCollection" );
                }
            }
        }

        [XmlIgnore]
        public ObservableCollection<UserBadge> BadgesCollection
        {
            get
            {
                if ( this.badgesCollection == null )
                    this.badgesCollection = new ObservableCollection<UserBadge>();

                return this.badgesCollection;
            }
            set
            {
                if ( this.badgesCollection != value )
                {
                    this.badgesCollection = value;
                    this.NotifyPropertyChanged( "BadgesCollection" );
                }
            }
        }

        [XmlIgnore]
        public ObservableCollection<Player> PlayerConnections
        {
            get
            {
                if ( this.playerConnections == null )
                    this.playerConnections = new ObservableCollection<Player>();

                return this.playerConnections;
            }
            set
            {
                if ( this.playerConnections != value )
                {
                    this.playerConnections = value;
                    this.NotifyPropertyChanged( "PlayerConnections" );
                }
            }
        }

        [XmlIgnore]
        public ObservableCollection<int> GameLevelCollectionWorkaround
        {
            get
            {
                return this.gameLevelCollectionWorkaround;
            }
            set
            {
                if ( this.gameLevelCollectionWorkaround != value )
                {
                    this.gameLevelCollectionWorkaround = value;
                    this.NotifyPropertyChanged( "GameLevelCollectionWorkaround" );
                }
            }
        }

        [XmlIgnore]
        public double RationedExperience
        {
            get
            {
                return this.rationedExperience;
            }
            set
            {
                if ( this.rationedExperience != value )
                {
                    this.rationedExperience = value;
                    this.NotifyPropertyChanged( "RationedExperience" );
                }
            }
        }
    }
}
